<?php
/**
 * 礼物业务类
 */
class core_service_gift extends core_service {
	protected $id;
	protected $marter_table = 'core_model_gift';

	/**
	 * 实例化对象
	 * @param int $id
	 */
	public function __construct($id = 0) {
		parent::__construct();
		$this->id = $id;
	}
	
	/**
	 * 新增礼物
	 * @param array $data
	 */
	function create($data = array()){
		if(!$data['gift_name'] or !$data['rank']){
			$this->setError(0, "缺少必要参数");
			return false;
		}
		$this->set('gift_name', $data['gift_name']);
		$this->set('intro', $data['intro']);
		$this->set('rank', intval($data['rank']));
		if($data['pic_url']) $this->set('pic_url', $data['pic_url']);
		if($data['stock']) $this->set('stock', intval($data['stock']));
		if($data['price']) $this->set('price', $data['price']);
		$this->set('create_time', $this->_time);
		return $this->save();
	}
	
	/**
	 * 修改礼物
	 * @param array $data
	 */
	function edit($data = array()){
		if(!$this->id) return false;
		if($data['gift_name']) $this->set('gift_name', $data['gift_name']);
		if($data['rank']) $this->set('rank', intval($data['rank']));
		if($data['pic_url']) $this->set('pic_url', $data['pic_url']);
		if($data['stock']) $this->set('stock', intval($data['stock']));
		if($data['price']) $this->set('price', $data['price']);
		if($data['create_time']) $this->set('create_time', $this->_time);
		return $this->save();
	}
}